import { PipeTransform, Injectable, BadRequestException } from '@nestjs/common';
import { PaginationDto } from '../dto/pagination.dto';

@Injectable()
export class PaginationPipe implements PipeTransform {
  transform(value: any): PaginationDto {
    const { page, limit } = value;
    if (isNaN(page) || isNaN(limit)) {
      throw new BadRequestException('Page and limit must be numbers');
    }
    return new PaginationDto(Number(page), Number(limit));
  }
}
